<template>
    <elm-page-bb>
        <el-form ref="model" :model="model" size="small" label-width="120px">
          <elm-row>
            <el-form-item label="计划" prop="plan">
              <elm-select-input :show-id="true" v-model="model.plan" url="/business/plm/check/GetPlanData"></elm-select-input>
            </el-form-item>
            <el-form-item label="质检人" prop="check_person" :rules="[{ required: true, message: '质检人必须填写'}]">
              <elm-ei v-model="model.check_person"></elm-ei>
            </el-form-item>
          </elm-row>
          <elm-row>
            <el-form-item label="产品" prop="product">
              <el-select v-model="model.product" style="width: 100%;" clearable>
                <el-option v-for="item in opt" :value="item.sys_code_key" :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="!model.product"></el-form-item>
            <el-form-item label="工序" prop="craft" v-if="model.product" :key="model.product">
              <elm-select-tree v-model="model.craft" url="/business/plm/product/craft/GetTree" path-url="/business/plm/product/craft/GetPath" :url-data="{pd_code:model.product}"></elm-select-tree>
            </el-form-item>
          </elm-row>
          <el-form-item label="附件">
            <elm-upload module_name="biz_plm_check_file" :rel_id="model.id" :multiple="true" :limit="10"  list-type="file" tip=""></elm-upload>
          </el-form-item>
          <el-form-item label="备注">
            <el-input type="textarea" v-model="model.remark" :rows="2"></el-input>
          </el-form-item>
        </el-form>
        <template #bottom>
            <el-button type="success" size="small" @click="submit" model.>立即保存</el-button>
            <el-button size="small" @click="close">取消</el-button>
        </template>
    </elm-page-bb>
</template>

<script>
export default {
    extends: elmVueBase,
    data() {
        return {
            model: {id:elm.newGuid(),create_time:new Date().toLocaleString('sv-SE').slice(0, 19).replace("T", " ")},
            opt:[]
        }
    },
  async created() {
    await this.getPd();
  },
  watch:{
    'model.product':{
      handler(newVal,oldVal){
        if(newVal!=oldVal)
          delete this.model.craft;
      },
      deep:true
    }
  },
  destroyed() {
    this.request.callVue.tablebinding();
  },
  methods: {
    async submit() {
      await this.$refs["model"].validate();
      var res = await elm.post('/business/plm/check/Upsert', this.model);
      if (res == true) {
          this.close();
          this.v('保存成功。');
          this.request.callVue.tablebinding();
      }
      else {
          this.error('保存失败，请稍后尝试。');
      }
    },
    async getPd(){
      this.opt=await elm.post('/business/plm/check/GetProduct', {});
    }
  }
}
</script>

<style scoped>
</style>